<template>
    <body id="poster">
        <el-form class="login-container" label-position="left" label-width="0px">
            <h3 class="login-title">管理员登陆</h3>
            <el-form-item style="margin-bottom: 10px;heigth: 150%">
                <el-input type="text" v-model="loginForm.username" auto-complete="off" placeholder="请输入用户名"/>
            </el-form-item>
            <el-form-item style="margin-bottom: 10px;height: 150%">
                <el-input type="text" v-model="loginForm.password" auto-complete="off" placeholder="请输入密码"/>
            </el-form-item>
            <el-form-item style="width: 100%">
                <el-button type="primary" style="width: 50%;background: #505458;border: none" v-on:click="login">
                    登陆
                </el-button>
            </el-form-item>
        </el-form>
    </body>
</template>

<script>
export default {
    name: 'login',
    data() {
        return {
            loginForm: {
                username: '',
                password: ''
            },
            responseResult: []
        }
    },
    methods: {
        login() {
            this.$axios
                .post('/api/admin/login', {
                    username: this.loginForm.username,
                    password: this.loginForm.password
                })
                .then(response => {
                    console.log(response.data)
                    console.log(response.data.data.token)
                    if (response.data.code === 200) {
                        this.$router.replace({path: '/home'});
                        //全局存储token
                        localStorage["token"] = "Bearer "+response.data.data.token
                    }
                })
                .catch(response => {
                    console.log(response);
                })
        }
    }
}
</script>

<style scoped>
#poster {
    background:url("../assets/bg1.jpg") no-repeat;
    background-position: center;
    height: 100%;
    width: 100%;
    background-size: cover;
    position: fixed;
}

body {
    margin: 0px
}

.login-container {
    border-radius: 15px;
    background-clip: padding-box;
    margin: 90px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
}
  
.login-title {
    margin: 0px auto 20px auto;
    text-align: center;
    color: #505458;
}
</style>